﻿using Hazdryx.Drawing;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.ExceptionServices;

namespace EmotionsExtract.UITex
{
    /// <summary>
    /// UITex 静态帧
    /// </summary>
    public class Frame : IFrame
    {
        /// <summary>
        /// 索引
        /// </summary>
        public int Index { get; private set; }

        /// <summary>
        /// 此静态帧指向的 UITex 数据
        /// </summary>
        public UITexFile Parent { get; private set; }

        /// <summary>
        /// 未使用？
        /// </summary>
        public int Info { get; private set; }

        /// <summary>
        /// 此静态帧在 UITex 图像中的起始 X 坐标
        /// </summary>
        public int Left { get; private set; }

        /// <summary>
        /// 此静态帧在 UITex 图像中的起始 Y 坐标
        /// </summary>
        public int Top { get; private set; }

        /// <summary>
        /// 此静态帧的宽度
        /// </summary>
        public int Width { get; private set; }

        /// <summary>
        /// 此静态帧的高度
        /// </summary>
        public int Height { get; private set; }

        /// <summary>
        /// 此静态帧是否被动画引用
        /// </summary>
        public bool UsedByAnimation { get; internal set; } = false;

        public Bitmap GetImage()
        {
            using (FastBitmap dst = new FastBitmap(this.Width, this.Height))
            {
                this.Parent.Image.CopyTo(dst, this.Left, this.Top, this.Width, this.Height);
                return new Bitmap(dst.BaseBitmap);
            }
        }

        public Frame(int index, UITexFile parent, int info, int left, int top, int width, int height)
        {
            this.Index = index;
            this.Parent = parent;
            this.Info = info;
            this.Left = left;
            this.Top = top;
            this.Width = width;
            this.Height = height;
        }
    }
}
